<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function fun() {
            alert(arguments.length);//3
            alert("无参函数");
            for (var i = 0; i < arguments.length; i++) {
                alert(arguments[i]);
            }
        }
        //fun(5, 24, "df");

        //需求：要求编写一个函数，用于计算所有参数相加的和并返回
        function add(num1, num2) {
            var sum = 0;
            for (var i = 0; i < arguments.length; i++) {
                sum += arguments[i];
            }
            return sum;
        }
        let result = add(12, 32, 234, 23, 123);
        alert(result);//424

        let result2 = add(12, 32, "abc", 23, 123);
        alert(result2);//44abc23123

        function add2(num1, num2) {
            var sum = 0;
            for (var i = 0; i < arguments.length; i++) {
                if (typeof(arguments[i]) == "number") {
                    sum += arguments[i];
                }
            }
            return sum;
        }
        let result3 = add2(12, 32, "abc", 23, 123);
        alert(result3);//190
    </script>
</head>
<body>

</body>
</html>